# -*- coding: utf-8 -*-
"""
__mktime___ = 'Just'
__filename_ = '2019/4/13'
__author__ = 'serverger'
"""
from werkzeug.exceptions import HTTPException
from app import create_app
from app.libs.error import APIException
from flask_cors import CORS


app = create_app()

# 全局跨域
CORS(app, supports_credentials=True)


# 全局异常拦截
@app.errorhandler(Exception)
def framework_error(e):
    if isinstance(e, APIException):
        return e
    if isinstance(e, HTTPException):
        code = e.code
        msg = e.description
        error_code = 1900
        return APIException(code, msg, error_code)
    else:
        if not app.config['DEBUG']:
            raise APIException()
        else:
            raise e


if __name__ == '__main__':
    """启动内置服务器"""
    # app.logger.info('启动内置服务器')
    app.run(host='0.0.0.0', debug=app.config['DEBUG'])
